package com.jd.tuning.jvm.async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.concurrent.Future;


/**
 * Async方式的异步化
 */
@Component
public class AsyncJob {

    @Async
    public  void saveOpLog() throws InterruptedException {
        Thread.sleep(1000L);
        System.out.println(new Date()+"插入操作日志");
    }


    @Async
    public Future<String> saveOpLogStr() throws InterruptedException {
        Thread.sleep(1000L);
        System.out.println(new Date()+"插入操作日志");
        return new AsyncResult<>("abc");
    }

}
